/*
 * @Author: your name
 * @Date: 2020-07-22 10:18:16
 * @LastEditTime: 2020-07-24 13:08:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tinkjsDemo\src\controller\base.js
 */ 
module.exports = class BaseController extends think.Controller {
  __before() {

  }

  /**
     * ajax请求统一的返回格式
     * @param result 结果集
     * @param msg  提示信息
     * @param errorno 错误号
     * @returns {{success: boolean, msg: string, result: all,errorno:number}}
     */
    successJson(result = {}, msg = '操作成功', errorno = 0) {
      if (arguments.length === 1 && typeof arguments[0] === 'string') {
          msg = arguments[0];
          result = {};
      }
      let obj = {
          result: result,
          msg: msg,
          errorno: errorno,
          success: true,
      };
      this.type = this.config('jsonContentType');
      this.body = obj;
      return false;
  }

  /**
     * ajax请求统一错误消息返回格式
     * @param result  结果集
     * @param msg   提示信息
     * @param errorno  错误号
     * @returns {{success: boolean, msg: string, result: {}, attributes: {}}}
     */
    errorJson(result = {}, msg = '操作失败', errorno = 1) {
      if (arguments.length === 1 && typeof arguments[0] === 'string') {
          msg = arguments[0];
          result = {};
      }
      let obj = {
          result: result,
          msg: msg,
          errorno: errorno,
          success: false,
      };
      this.type = this.config('jsonContentType');
      this.body = obj;
      return false;
  }
};
